﻿namespace EFS.RC.CC.Deployment.Tables.Tools
{
	public static class OfficeEndPoints
	{
		/// GetAll
		public static EFS.RC.CC.Deployment.Entities.EndPoints.Office[] GetAll()
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// get data
				return connection.DoExecuteTableReaderQuery<EFS.RC.CC.Deployment.Entities.EndPoints.Office>(
					"[dbo].[OfficeEndPoints_GetAll]", 
					null, 
					EFS.RC.CC.Deployment.Tables.DataRow.EndPoints.Office.Load);
			}
		}

		/// GetByID
		public static EFS.RC.CC.Deployment.Entities.EndPoints.Office GetByID(System.Int32 id)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// get data
				return connection.DoExecuteRowReaderQuery<EFS.RC.CC.Deployment.Entities.EndPoints.Office>(
					"[dbo].[OfficeEndPoints_GetByID]",
					new EFS.DB.Parameters.Array("id", id), 
					EFS.RC.CC.Deployment.Tables.DataRow.EndPoints.Office.Load);
			}
		}

		/// GetBySIP
		public static EFS.RC.CC.Deployment.Entities.EndPoints.Office GetBySIP(System.String sip)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// get data
				return connection.DoExecuteRowReaderQuery<EFS.RC.CC.Deployment.Entities.EndPoints.Office>(
					"[dbo].[OfficeEndPoints_GetBySip]",
					new EFS.DB.Parameters.Array("sip", sip),
					EFS.RC.CC.Deployment.Tables.DataRow.EndPoints.Office.Load);
			}
		}

		/// Create
		public static System.Int32? Create(
			System.String sip)
		{
			// make params
			EFS.DB.Parameters.Array parametersArray = new EFS.DB.Parameters.Array(
				new System.String[] { "sip", "id" },
				new System.Object[] { sip, default(System.Int32) },
				new System.Boolean[] { false, true });

			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// ok
				connection.DoExecuteNonQuery("[dbo].[OfficeEndPoints_Create]", parametersArray);
			}

			// get id vaoue
			return parametersArray.GetOutPrameterValue<System.Int32?>("id"); 
		}

		/// Update
		public static void Update(System.Int32 id, System.String sip)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				connection.DoExecuteNonQuery(
					"[dbo].[OfficeEndPoints_Update]",
					new EFS.DB.Parameters.Array(
							new System.String[] { "id", "sip" },
							new System.Object[] { id, sip }));
			}
		}

		/// Delete
		public static void Delete(System.Int32 id)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				connection.DoExecuteNonQuery("[dbo].[OfficeEndPoints_Delete]", new EFS.DB.Parameters.Array("id", id));
			}
		}
	}

}